package com.boot2523.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.boot2523.bean.Dept;
import com.boot2523.bean.Dept2;
import com.boot2523.mapper.DeptMapper;
import com.boot2523.mapper.DeptPlusMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
@Service
public class DeptS implements DeptMapper {
    @Resource
    public DeptMapper dm;
    @Override
    public int insert(Dept d) {
        return dm.insert(d);
    }

    @Override
    public int delete(int id) {
        return dm.delete(id);
    }

    @Override
    public int update(Dept d) {
        return dm.update(d);
    }

    @Override
    public List<Dept> all() {
        return dm.all();
    }

    @Override
    public Dept one(int id) {
        return dm.one(id);
    }

    @Override
    public List<Dept> page(int begin, int len) {
        return dm.page(begin,len);
    }
    public PageInfo<Dept> page2(int cur,int len){
        //设置当前页及长度
        PageHelper.startPage(cur,len);
        //查询所有
        List<Dept> data=dm.all();
        return new PageInfo<>(data);
    }
    @Resource
    public DeptPlusMapper dpm;

    /**
     * 查询所有
     * @return
     */
    public List<Dept2> all2(){
        return dpm.selectList(null);
    }

    /**
     * 查询一条
     * @param id
     * @return
     */
    public Dept2 one2(int id){
        return dpm.selectById(id);
    }
    public Dept2 one3(String name){
        //查询条件构造器
        LambdaQueryWrapper<Dept2> wrapper=new LambdaQueryWrapper<>();
        //设置条件
        //eq()  =
        //ne()  <>
        //gt() >=
        //lt() <=
        //like() 模糊查询
        //in() 区间查询
        wrapper.eq(Dept2::getLoc,name);
        return dpm.selectOne(wrapper);
    }
}
